Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CustomKey for a customized signing and verifying #52

Closed
wants to merge 1 commit into from

Conversation

jc-lab
Copy link

@jc-lab jc-lab commented Oct 19, 2019

  • Add CustomKey for a customized signing and verifying

  • This is can be support JWT signing via KMS like GCP-KMS.

sample code:

const { JWT, JWK, KeyObject } = require('jose')

class CustomKey extends JWK.CustomKey {
  constructor () {
    super({ alg: 'EC', use: 'sig', kid: '12345678', ops: ['sign', 'verify'], keyType: 'private' })
  }

  toPEM (priv, encoding) {
    return undefined
  }

  algorithms (operation) {
    return new Set(['ES256'])
  }

  sign (alg, buffer) {
    console.log('sign invoked: ', alg)
    return 'BASE_64_ENCODED_SIGNATURE'
  }

  verify (alg, buffer) {
    console.log('verify invoked: ', alg)
    return true
  }
}

const customKey = new CustomKey()

const encoded = JWT.sign({}, customKey, {
  expiresIn: '600s'
})

console.log('encoded : ', encoded)

const decoded = JWT.verify(encoded, customKey)

console.log('decoded : ', decoded)

@jc-lab jc-lab force-pushed the support-customkey branch from b7efe59 to 4998ce5 Compare October 19, 2019 10:34
@panva
Copy link
Owner

panva commented Oct 19, 2019

Hi @jc-lab

GCP-KMS, and i imagine others too, are not going to respond synchronously which is a prerequisite for this being compatible with the sync node crypto API and therefore the sync API of this library.

I struggle to find the use for this and the example in your description is light on an actual implementation.

Thoughts?

@jc-lab
Copy link
Author

jc-lab commented Oct 19, 2019

Hi @panva

Thank you for comment.

I wonder why You don't consider the async function.

Is it to ensure always sync?

@panva
Copy link
Owner

panva commented Oct 20, 2019

Why would I write an asynchronous API when node crypto is entirely synchronous. There’s no good reason to.

@panva panva closed this Oct 23, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants